
//--------------------------------------------------------------------------------------------------------------------------
//	Message object
//--------------------------------------------------------------------------------------------------------------------------

//Type = I (information) W (warning) V (valid) E (error)


function Message (text,type)
{
	var copy = text.replace(new RegExp(/_br_/g), "<br>"); 
	this.text = copy;	
	this.type = type;
	
	this.toHTML = Message_toHTML;
}

function Message_toHTML()
{
	switch (this.type)
	{
		//Error
		case "E" :
		case "e" :
			return "<div class='tooltip message_error'><img src='images/exclamation.png' class='imgTooltip'><div style='float:right;clear:both;'>"+this.text+"</div></div>";
			break;
		//Warning
		case "W" :
		case "w":
			return "<div class='tooltip message_warning'><img src='images/exclamation.png' class='imgTooltip'><div style='float:right;clear:both;'>"+this.text+"</div></div>";
			break;
		//Loading
		case "L" :
		case "l":
			return "<div class='tooltip message_info'><img src='images/tooltiploading.gif' class='imgTooltip'><div style='float:right;clear:both;'>"+this.text+"</div></div>";
			break;
		//Information		
		case "V" :
		case "v":
		case "I" :
		case "i":
			return "<div class='tooltip message_info'><img src='images/information.png' class='imgTooltip'><div style='float:right;clear:both;'>"+this.text+"</div></div>";
			break;
    default:
      return "";
      break;
	}
}	

//--------------------------------------------------------------------------------------------------------------------------

function DisplayMessage(text,type,idMessage)
{
	var messageObj = new Message(text,type);
	idMessage = idMessage || " ";
	showMessage(messageObj);
}

function showMessage(messageObj)
{
	var divMessage = $("#divMessagePage"+messageObj.type.toUpperCase());
	var divTexte = $(".texte_message",divMessage);
	
	divTexte.html(messageObj.text);
	divMessage.css("visibility","hidden").css("display","");
	
	if (divTexte.height()>50)
		{divTexte.css("height","50px");}
	
	divMessage.css("visibility","visible").css("display","none");
	
	if (messageObj.type.toUpperCase() == "B")
		{putScreenCache("message");}
	
	setTimeout("$(\"#divMessagePage"+messageObj.type.toUpperCase()+"\").fadeIn(400,function(){execOnResizeEvents();})",500);
	
	if (messageObj.type.toUpperCase() != "E" && messageObj.type.toUpperCase() != "W")
		{setTimeout(function() {hideMessage();},5000);}
}

function hideMessage()
{
	$(".divMessagePage:visible").fadeOut(500,function(){afterFadeOutMessage();});
}

function afterFadeOutMessage()
{
	removeScreenCache("message_modal");
	var divMessage = $(".divMessagePage:visible");
	var divTexte = $(".texte_message",divMessage);
	divTexte.html("");
	divTexte.css("height","");
	divMessage.css("display","none").css("visibility","visible");	
	execOnResizeEvents();	
}

function closeModalWinMessage(idMessage)
{
	cacherModalWin('message_modal');
	if(document.location.host != "localhost")
		{ecrireCookie(nomCookieService, idMessage, "cm.net");}
	else
		{ecrireCookie(nomCookieService, idMessage);}
}